package com.jf3q.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jf3q.common.domain.EduCourse;
import com.jf3q.common.domain.EduTeacher;
import com.jf3q.common.vo.ResultVo;
import com.jf3q.front.service.CourseService;
import com.jf3q.front.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    TeacherService teacherService;
    @Autowired
    CourseService courseService;


    //1 分页查询讲师的方法
    @PostMapping("/{page}/{limit}")
    public ResultVo getTeacherFrontList(@PathVariable long page, @PathVariable long limit) {
        Page<EduTeacher> pageTeacher = new Page<>(page,limit);
        Map<String,Object> map = teacherService.getTeacherFrontList(pageTeacher);
        //返回分页所有数据
        return ResultVo.success(map);
    }

    //2 讲师详情的功能
    @GetMapping("/{teacherId}")
    public ResultVo getTeacherFrontInfo(@PathVariable String teacherId) {
        //1 根据讲师id查询讲师基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);
        //2 根据讲师id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);

        Map map = new HashMap<>();
        map.put("teacher",eduTeacher);
        map.put("courseList",courseList);
        return ResultVo.success(map);
    }
}
